<?php
namespace app\admin\model;

use \think\Model;
class ArticleCat extends \think\Model{
    protected $table = 'edu_article_cat';
    protected $pk = "cat_id";
    public function getTree(){
        $data=$this->select();
        return $this->makeTree($data);

    }
        
    
    public function makeTree($data,$pid=0,$count=0){
        static $arr=array();
        foreach ($data as $k => $v){
            if($v['cat_fid']==$pid){
                $v['count']=$count;
                $arr[]=$v;
                unset($data[$k]);
                $this->makeTree($data,$v['cat_id'],$count+1);
            }
        }
        return $arr;
    }

    public function article(){
        return $this->hasMany('Article','cat_id','cat_id');

    }
}
